//
//  CurrentDayItems.m
//  qulvyou
//
//  Created by mmyy on 15/10/22.
//  Copyright (c) 2015年 mmyy. All rights reserved.
//

#import "CurrentDayItems.h"
#import "CoreData+MagicalRecord.h"
@implementation CurrentDayItems
@dynamic cover_image;
@dynamic cover_image_height;
@dynamic cover_image_width;
@dynamic text;
@dynamic spot_id;
@dynamic avatar_l;
@dynamic name;

+(instancetype)currentDayItemsWithDict:(NSDictionary *)dict
{
    CurrentDayItems *items = [CurrentDayItems MR_createEntity];
    items.cover_image = dict[@"cover_image"];
    items.cover_image_height = dict[@"cover_image_height"];
    items.cover_image_width = dict[@"cover_image_width"];
    items.text = dict[@"text"];
    items.spot_id = [dict[@"spot_id"] stringValue];
    items.avatar_l = [dict[@"user"] objectForKey:@"avatar_l"];
    items.name = [dict[@"user"] objectForKey:@"name"];
    [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
    
    return items;

}

+(NSArray *)getAllDataFromCoreData
{
    NSArray *array = [CurrentDayItems MR_findAll];
    return array;
}

+(void)removeAllData
{
    NSArray *array = [CurrentDayItems MR_findAll];
    for (CurrentDayItems *items in array) {
        [items MR_deleteEntity];
        [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
    }
}

@end
